package com.example.demo.struct.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Desc:
 * @Author zzz
 * @Date 2021/2/24
 * @Version V1.0
 */
public class Computer implements Component {

    List<Component> componentList = new ArrayList<>();

    public Computer add(Component component) {
        componentList.add(component);
        return this;
    }

    public void remove(Component component) {
        componentList.remove(component);
    }


    @Override
    public double calc() {
        double sum = 0;
        for (Component component : componentList) {
            sum += component.calc();
        }
        return sum;
    }

    @Override
    public void display() {
        for (Component component : componentList) {
            component.display();
        }
    }
}
